package com.ecable.serviceImpl;

import java.util.Vector;

import com.ecable.bean.VillageTO;
import com.ecable.daoI.VillageDaoI;
import com.ecable.daoImpl.VillageDaoImpl;
import com.ecable.exception.ConnectionException;
import com.ecable.exception.DataNotFoundException;
import com.ecable.exception.LoginException;
import com.ecable.serviceI.VillageServiceI;

public class VillageServiceImpl implements VillageServiceI{

	
	VillageDaoI vdaoi=new VillageDaoImpl();
	boolean flag=false;
	VillageTO vto=null;
	
	
public boolean insertVillage(VillageTO vto)throws LoginException,ConnectionException{
	
	flag= vdaoi.insertVillage(vto);
	
	
	if(flag==false)
	{
		
		throw new ConnectionException();
		
	}
	else if (vto.getSname()==null || vto.getSname().equals("")) {
		
		
		throw new LoginException();
		}
	return flag;
}
	

	
	public VillageTO  viewVillageAt(int vid1) throws ConnectionException,DataNotFoundException{
		
		 vto= vdaoi.viewVillageAt(vid1); 
		 
		 
		 if(vto==null)
			{
				throw new DataNotFoundException();
				
			}
			
			return vto;
			
		
	}
	public Vector<VillageTO > viewVillage()throws ConnectionException,DataNotFoundException{
		
		
		
		Vector<VillageTO > vto= vdaoi.viewVillage();
		
		
		if(vto==null)
		{
			throw new ConnectionException();
			
		}
		else if (vto.isEmpty()) {
			
			throw new DataNotFoundException();
			
		}
		return vto;
		
	}
	
	public boolean deleteVillage(int vid) throws ConnectionException{
		
		
		flag= vdaoi.deleteVillage(vid);
		
		if(flag==false){
			
			throw new ConnectionException();
			}
		
		return flag;
		
	}
	public boolean updateVillage(VillageTO sf)throws ConnectionException{
		
		
		
		flag= vdaoi.updateVillage(sf);
		
		if(flag==false){
			
			throw new ConnectionException();
		}
		return flag;
		
		
	}
	
	public Vector<VillageTO > viewVillage(String sname,String dname)throws ConnectionException,DataNotFoundException{
		
		
		
		
		Vector<VillageTO > vto=vdaoi.viewVillage(sname, dname);
		
		
		if(vto==null)
		{
			throw new ConnectionException();
			
		}
		else if (vto.isEmpty()) {
			
			throw new DataNotFoundException();
			
		}
		return vto;
		
	}
public Vector<VillageTO > getVillageName(String dname)throws ConnectionException,DataNotFoundException{
		
		
		
		
		Vector<VillageTO > vto=vdaoi.getVillageName(dname);
		
		
		if(vto==null)
		{
			throw new ConnectionException();
			
		}
		else if (vto.isEmpty()) {
			
			throw new DataNotFoundException();
			
		}
		return vto;
		
	}
	
	
	
}
